package com.bianmaba.dc.task;

import com.bianmaba.dc.bean.CollectionData;
import com.bianmaba.dc.bean.CollectionRequest;
import com.bianmaba.dc.bean.DataType;
import com.bianmaba.dc.supports.services.AbstractCollectionService;
import org.apache.commons.lang3.time.DateUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

@Service
public class DtsCollectionService extends AbstractCollectionService {


    @Override
    public CollectionData.Table collectionProjectStatistics(CollectionRequest request) throws Exception {
        List<CollectionData.Row> rows = new ArrayList(0);
        Date st = DateUtils.parseDate(request.getCollectionParameters().get("startDate"), "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy-MM-dd", "yyyy/MM/dd");
        Date et = DateUtils.parseDate(request.getCollectionParameters().get("endDate"), "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy-MM-dd", "yyyy/MM/dd");

        CollectionData.Row row = CollectionData.Row.of(new HashMap() {{
            put("发现问题个数", 110);
            put("关闭问题个数", 95);
            put("严重问题个数", 18);
            put("一般问题个数", 43);
            put("提示问题个数", 49);
        }}, st, et);
        rows.add(row);
        return CollectionData.Table.of(DataType.PROJECT_STATISTICS, rows);
    }

    @Override
    public CollectionData.Table collectionWorkforceStatistics(CollectionRequest request) throws Exception {
        List<CollectionData.Row> rows = new ArrayList(0);
        Date st = DateUtils.parseDate(request.getCollectionParameters().get("startDate"), "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy-MM-dd", "yyyy/MM/dd");
        Date et = DateUtils.parseDate(request.getCollectionParameters().get("endDate"), "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy-MM-dd", "yyyy/MM/dd");

        CollectionData.Row row = CollectionData.Row.of(new HashMap() {{
            put("姓名", "刘博兴");
            put("工号", "0000150966");


            put("发现问题个数", 10);
            put("关闭问题个数", 8);
            put("严重问题个数", 1);
            put("一般问题个数", 5);
            put("提示问题个数", 4);
        }}, st, et);
        rows.add(row);
        return CollectionData.Table.of(DataType.WORKFORCE_STATISTICS, rows);
    }

    @Override
    public CollectionData.Table collectionDemandStatistics(CollectionRequest request) throws Exception {
        List<CollectionData.Row> rows = new ArrayList(0);
        Date st = DateUtils.parseDate(request.getCollectionParameters().get("startDate"), "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy-MM-dd", "yyyy/MM/dd");
        Date et = DateUtils.parseDate(request.getCollectionParameters().get("endDate"), "yyyy-MM-dd HH:mm:ss", "yyyy/MM/dd HH:mm:ss", "yyyy-MM-dd", "yyyy/MM/dd");

        CollectionData.Row row = CollectionData.Row.of(new HashMap() {{
            put("需求编号", "0001");
            put("需求名称", "需求名称");
            put("检视问题个数", 8);
            put("预估工作量", 4);
            put("实际工作量", 5);
        }}, st, et);
        rows.add(row);
        return CollectionData.Table.of(DataType.DEMAND_STATISTICS, rows);
    }

    @Override
    public CollectionData.Table collectionSourceData(CollectionRequest request) {
        List<CollectionData.Row> rows = new ArrayList(0);
        for (int i = 0; i < 5; i++) {
            String no = "0000" + (i + 1);
            CollectionData.Row row = CollectionData.Row.of(new HashMap() {{
                put("问题单号", no);

                put("创建人", "小张");
                put("创建人工号", "0000004521");
                put("责任人", "陈家彬");
                put("责任人工号", "0000004114");

                put("创建时间", "2019-01-10");
                put("状态", "已关闭");
                put("关闭时间", "2019-01-11");
                put("问题单描述", "描述信息");
                put("严重呈度", "提示");
            }});
            rows.add(row);
        }
        rows.get(0).getDatas().put("严重呈度", "严重");

        for (int i = 0; i < 5; i++) {
            String no = "0000" + (i + 1);
            CollectionData.Row row = CollectionData.Row.of(new HashMap() {{
                put("问题单号", no);

                put("创建人", "小牛");
                put("创建人工号", "0000004522");
                put("责任人", "陈家彬");
                put("责任人工号", "0000004114");

                put("创建时间", "2019-01-10");
                put("状态", "已关闭");
                put("关闭时间", "2019-01-11");
                put("问题单描述", "描述信息");
                put("严重呈度", "一般");
            }});
            rows.add(row);
        }
        return CollectionData.Table.of(DataType.SOURCE_DATA, rows);
    }
}
